package com.example.urltovoice.service.impl;

import com.example.urltovoice.service.ICrawlService;
import com.example.urltovoice.util.Crawling;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class WxCrawlService implements ICrawlService {
    @Override
    public String crawlService(String url) {
        ArrayList<String> texts = new ArrayList();
        Elements infoListEle = Crawling.crawlService(url).getElementsByClass("rich_media_content");
        infoListEle.forEach(element -> texts.add(element.getElementsByTag("p").text()));
        if(texts.size() == 0){
            return null;
        }else{
            return texts.get(0);
        }

    }
}
